/**
 * goio-bean
 *
 * This class is the base Bean for all beans objects
 *
 * @link http://www.marcosperon.com/
 * @copyright 2009 - Peron Co.
 *
 * @author Marcos Peron @package com.marcosperon.bean
 * @version 2009
 */
package com.mperon.bean;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;

/**
 * The Class Bean.
 */
@MappedSuperclass
public abstract class Bean implements Serializable, Comparable<Bean> {

    /**
     * The Constant serialVersionUID.
     */
    private static final long serialVersionUID = 3163408841639407668L;
    /**
     * The id.
     */
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "id", updatable = false, nullable = false)
    private Long id = null;
    /**
     * The active.
     */
    @Column(name = "active", nullable = false)
    private boolean active = true;

    /**
     * Instantiates a new bean.
     */
    public Bean() {
        // hello do something here
    }

    /**
     * Sets the id.
     *
     * @param id the new id
     */
    protected void setId(final Long id) {
        this.id = id;
    }

    /**
     * Gets the id.
     *
     * @return the id
     */
    public Long getId() {
        return id;
    }

    /**
     * Checks if is active.
     *
     * @return true, if is active
     */
    public boolean isActive() {
        return active;
    }

    /**
     * Sets the active.
     *
     * @param active the new active
     */
    public void setActive(boolean active) {
        this.active = active;
    }

    /**
     * 
     * @param source
     */
    protected void copy(final Bean source) {
        this.id = source.id;
        this.active = source.active;
    }

    /*
     * (non-Javadoc)
     *
     * @see java.lang.Comparable#compareTo(java.lang.Object)
     */
    @Override
    public int compareTo(Bean obj) {
        return id.compareTo(obj.getId());
    }

    /*
     * (non-Javadoc)
     *
     * @see java.lang.Object#equals(java.lang.Object)
     */
    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Bean other = (Bean) obj;
        if (id != other.id && (id == null || !id.equals(other.id))) {
            return false;
        }
        return true;
    }

    /*
     * (non-Javadoc)
     *
     * @see java.lang.Object#hashCode()
     */
    @Override
    public int hashCode() {
        int hash = 7;
        hash = 37 * hash + (id != null ? id.hashCode() : 0);
        return hash;
    }
}
